package com.hmall.trade.listener;

import com.hmall.common.constants.MQConstants;
import com.hmall.trade.service.IOrderService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;


/**
 * 订单支付成功监听器
 */
@Component
@Slf4j
@RequiredArgsConstructor
public class PayStatusListener {

    private final IOrderService orderService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = MQConstants.PAY_QUEUE_NAME, durable = "true"),
            exchange = @Exchange(name = MQConstants.PAY_EXCHANGE_NAME),
            key = MQConstants.PAY_ROUTING_KEY
    ))
    public void listenPaySuccess(Long orderId){
        log.info("收到支付成功消息，订单号：{}",orderId);
        orderService.markOrderPaySuccess(orderId);
        log.info("订单状态已修改，订单号：{}",orderId);
    }
}